#!/bin/zsh

### Setup antidote.
#function __antidote_setup {
  0=${(%):-%x}
  fpath=( "${0:A:h}" $fpath )
  local fn
  for fn in ${0:A:h}/*; do
    [[ ${fn:t} != '__antidote_setup' ]] || continue
    if typeset -f ${fn:t} > /dev/null; then
      unfunction -- ${fn:t}
    fi

    # autoload extensionless function files
    [[ -z "${fn:e}" ]] && autoload -Uz "${fn}"
  done

  # man pages
  if [[ "$MANPATH" != *"${0:A:h:h}/man"* ]]; then
    export MANPATH="${0:A:h:h}/man:$MANPATH"
  fi

  builtin autoload -Uz is-at-least
  if is-at-least 5.8; then
    # -D : Delete flags from the param array once they are detected
    # -M : Map a flag to alternative names (useful for defining -s(hort) and --long options)
    # -F : Fail if a flad is provided that was not defined in the zparseops spec
    # the -F option was added in 5.8
    typeset -gHa _adote_zparopt_flags=( -D -M -F )
  else
    typeset -gHa _adote_zparopt_flags=( -D -M )
  fi

  typeset -gHa _adote_funcopts=( extended_glob no_monitor pipefail )
  if zstyle -t ':antidote:tests' set-warn-options; then
    typeset -gHa _adote_funcopts=( $_adote_funcopts warn_create_global warn_nested_var )
  fi

  gawk --version &>/dev/null && typeset -gH __adote_awkcmd=gawk || typeset -gH __adote_awkcmd=awk
  typeset -gHi __adote_ksh_arrays
  typeset -gHi __adote_sh_glob
#}
